/**
 * 
 */
package vue.popup;

import java.awt.event.ActionEvent;

import javax.swing.JMenuItem;

import vue.desktop.IGDeskCNFUse;
import controller.ISessionManager;

/**
 * @author GRONOWSKI Stephane svan001@aol.com
 * 
 *         igsat 2010
 * 
 */
public class JPopupIGDeskCNFUse extends JPopupCNFUse {

	/**
	 * 
	 */
	private static final long	serialVersionUID	= 1L;
	public static final String	ITEM_HIDE_STAT		= "Hide stat";
	public static final String	ITEM_SHOW_STAT		= "Show stat";

	protected JMenuItem			showStatItem;
	protected JMenuItem			hideStatItem;

	protected IGDeskCNFUse		cnfuse;

	/**
	 * @param cnfuse
	 * @param manager
	 */
	public JPopupIGDeskCNFUse(IGDeskCNFUse cnfuse, ISessionManager manager) {
		super(cnfuse.getCnfuse(), manager);
		// TODO Auto-generated constructor stub
		this.cnfuse = cnfuse;
	}


	/**
	 * Create the pop up menu for the {@link IGDeskCNFUse}.
	 */
	@Override
	protected void createMenu() {
		super.createMenu();

		// show et hide stat
		showStatItem = new JMenuItem(ITEM_SHOW_STAT);
		showStatItem.addActionListener(this);

		add(showStatItem);

		hideStatItem = new JMenuItem(ITEM_HIDE_STAT);
		hideStatItem.addActionListener(this);

		add(hideStatItem);
	}

	@Override
	public void refresh() {
		super.refresh();
		if (cnfuse.getShowStat())
		{// montre les stat
			hideStatItem.setEnabled(true);
			showStatItem.setEnabled(false);
		}
		else
		{// montre pas les stat
			hideStatItem.setEnabled(false);
			if (cnfuse.getCnfuse().getCnfuse().getCnf().getStat() != null)
				showStatItem.setEnabled(true);
			else
				showStatItem.setEnabled(false);
		}
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		super.actionPerformed(e);

		if (e.getSource() == showStatItem)
		{// check stat
			cnfuse.showStat(true);
			return;
		}
		if (e.getSource() == hideStatItem)
		{// export
			cnfuse.showStat(false);
			return;
		}
	}
}
